package br.com.android.pubclub.web;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.android.pubclub.R;
import br.com.android.pubclub.basicas.Cliente;

public class ClientesAdapter extends BaseAdapter {
	
	private ArrayList<Cliente> listaDeClientes;
	
	
	public ClientesAdapter(ArrayList<Cliente> listaDeClientes){
		
		this.listaDeClientes = listaDeClientes;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listaDeClientes.size();
	}

	@Override
	public Cliente getItem(int position) {
		// TODO Auto-generated method stub
		return listaDeClientes.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return Integer.valueOf(listaDeClientes.get(position).getId_cliente());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		   Holder holder;  
		   Context ctx = parent.getContext();
		   
		   Cliente cli = listaDeClientes.get(position);  
		  
		   if (convertView == null){  
			   
		      convertView = LayoutInflater.from(ctx).inflate(  
		        R.layout.lista_de_clientes_linha, null);  
		   
		      holder = new Holder();  
		      holder.txtNome = (TextView)   
		         convertView.findViewById(R.id.txtNome);  
		      holder.txtEmail = (TextView)   
		         convertView.findViewById(R.id.txtEmail);  
		      convertView.setTag(holder);  
		   } else {  
		      holder = (Holder)convertView.getTag();  
		   }  
		   holder.txtNome.setText(cli.getNome());  
		   holder.txtEmail.setText(cli.getEmail());  	
		  
		   return convertView;  
		
		
		
		
		
	}
	
	static class Holder {
	
		TextView txtNome;
		TextView txtEmail;
		
	}
		
	

}
